package com.phone.modules.pms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.phone.modules.pms.model.PmsBrand;
import com.phone.modules.pms.mapper.PmsBrandMapper;
import com.phone.modules.pms.service.PmsBrandService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 品牌表 服务实现类
 * </p>
 *
 * @author WangHao
 * @since 2022-04-14
 */
@Service
public class PmsBrandServiceImpl extends ServiceImpl<PmsBrandMapper, PmsBrand> implements PmsBrandService {

    /**
     * 根据品牌名称分页获取品牌列表
     * @param keyword 品牌名称
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public Page listBrand(String keyword, Integer pageNum, Integer pageSize) {
        Page page = new Page(pageNum, pageSize);
        QueryWrapper<PmsBrand> queryWrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(keyword)) {
            queryWrapper.lambda().like(PmsBrand::getBrandName, keyword);
        }
        // 根据sort，顺序排序
        queryWrapper.lambda().orderByAsc(PmsBrand::getSort);
        return this.page(page, queryWrapper);
    }

    /**
     * 修改品牌信息
     * @param id
     * @param pmsBrand
     * @return
     */
    @Override
    public boolean updateBrand(Long id, PmsBrand pmsBrand) {
        pmsBrand.setId(id);
        return this.updateById(pmsBrand);
    }

    /**
     * 删除品牌
     * @param id
     * @return
     */
    @Override
    public boolean deleteBrand(Long id) {
        return this.removeById(id);
    }


    /**
     * 批量删除品牌
     * @param ids
     * @return
     */
    @Override
    public boolean deleteBrand(List<Long> ids) {
        return this.removeByIds(ids);
    }

}
